<?php

namespace App\Miya\Tools;


use Encore\Admin\Form\EmbeddedForm;

class ExtendTool
{
    static public function buildForm(EmbeddedForm &$form, $extendData)
    {
        foreach ($extendData as $key => $extend) {
            //获取组件
            $control = $extend['control'];
            //获取组件对象,并按照条件渲染
            $formObject = $form->$control($extend['name']);
            if (array_search($control, ['file', 'image']) !== false) {
                $formObject->uniqueName();
            }
            //金额组件修饰
            if ($control == 'currency') {
                $formObject->symbol('¥');
            }
            //开关组件修饰
            if ($control == 'switch') {
                $states = [
                    'on' => ['value' => 1, 'text' => "是"],
                    'off' => ['value' => 0, 'text' => '否'],
                ];
                $formObject->states($states);
            }
        }
    }
}
